import { app, BrowserWindow } from "electron";
import * as path from "path";
import { Disposable } from "./core/lifecycle";
import { IStateService } from "./services/stateService";
import { IThemeMainService } from "./services/themeMainService";

export class CodeApplication extends Disposable {
  constructor(
    @IStateService private readonly stateService: IStateService,
    @IThemeMainService private readonly themeService: IThemeMainService
  ) {
    super();
  }

  async startup(): Promise<void> {
    // this.logService.debug('Starting VS Code');
    const theme = this.themeService.getBackgroundColor();
    
    console.log("current theme: ", theme);
    console.log('Starting VS Code', this.stateService, this.themeService);

    const that = this;
    that.createWindow();
    app.on("activate", function () {
      // On macOS it's common to re-create a window in the app when the
      // dock icon is clicked and there are no other windows open.
      if (BrowserWindow.getAllWindows().length === 0) { 
        that.createWindow();
      }
    });

  }

  createWindow(): void {
    // Create the browser window.
    const mainWindow = new BrowserWindow({
      height: 600,
      webPreferences: {
        preload: path.join(__dirname, "../render/preload.js"),
      },
      width: 800,
    });

    // and load the index.html of the app.
    mainWindow.loadFile(path.join(__dirname, "../../index.html"));

    // Open the DevTools.
    mainWindow.webContents.openDevTools();
  }


}


